package com.yincai.carefreewater.callback;

import com.google.gson.internal.$Gson$Types;

import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import okhttp3.Call;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by $zhangke on 2017/5/16.
 *
 *
 */


//泛型T： 代表可以返回给主线程 什么类型的javaBean，比如是person 还是animal
public abstract class MyHttpCallback<T> {
    public Type type;
    static Type getSuperclassTypeParameter(Class<?> subclass){
        Type superclass =subclass.getGenericSuperclass();
        if(superclass instanceof Class){
            throw new RuntimeException("Missing type parameter");
        }
        ParameterizedType parameterized=(ParameterizedType)superclass;
        return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
    }
    public MyHttpCallback(){
        type=getSuperclassTypeParameter(getClass());
    }
    public abstract void onBeforeRequest(Request request);
    public abstract void onFailure(Call call, IOException e);
    public abstract void onSuccess(Response response, T t);
    public abstract void onError(Response response,String errorMsg);
}
